package com.javasm.mb_store_api_final.ordersys.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.mb_store_api_final.ordersys.order.dao.OrderTableDao;
import com.javasm.mb_store_api_final.ordersys.order.entity.OrderTable;
import com.javasm.mb_store_api_final.ordersys.order.service.OrderTableService;
import com.javasm.mb_store_api_final.sys_control.usercontrol.sys_user.entity.SysUser;
import org.springframework.stereotype.Service;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.List;

/**
 * (OrderTable)表服务实现类
 *
 * @author makejava
 * @since 2024-07-31 21:33:54
 */
@Service("orderTableService")
public class OrderTableServiceImpl extends ServiceImpl<OrderTableDao, OrderTable> implements OrderTableService {


    @Override
    public List<OrderTable> queryBy(OrderTable orderTable,Integer currentPage, Integer pageSize) {
        QueryWrapper<OrderTable> queryWrapper = new QueryWrapper<>();
        if (orderTable.getOid() != null) {
            queryWrapper.like("oid", orderTable.getOid());
        }
        if (orderTable.getUname() != null) {
            queryWrapper.like("uname", orderTable.getUname());
        }
        if (orderTable.getUname() != null) {
            queryWrapper.like("otype", orderTable.getOtype());
        }
        if (orderTable.getUname() != null) {
            queryWrapper.like("ostyle", orderTable.getOstyle());
        }

        if (orderTable.getOrderDate() != null) {
            System.out.println(orderTable.getOrderDate());
            queryWrapper.like("order_date", orderTable.getOrderDate());
        }
        if (orderTable.getOstate() != null) {
            queryWrapper.like("ostate", orderTable.getOstate());
        }
        Page<OrderTable> page = new Page<>(currentPage, pageSize);


        // 执行查询
        Page<OrderTable> page1 = this.page(page, queryWrapper);
        return page1.getRecords();

    }

    @Override
    public OrderTable getById(Integer oid) {
        QueryWrapper<OrderTable> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("oid", oid);
            return this.getOne(queryWrapper);

    }

    @Override
    public Integer gerOrderNum() {
        QueryWrapper<OrderTable> queryWrapper = new QueryWrapper<>();
        Integer a = 0;
        queryWrapper.eq("ostate", a);

        return Math.toIntExact(this.count(queryWrapper));
    }

    @Override
    public Integer gerNum() {
        QueryWrapper<OrderTable> queryWrapper = new QueryWrapper<>();

        return Math.toIntExact(this.count(queryWrapper));
    }


}

